package com.kang.controller;

import com.kang.bean.Dialogue;
import com.kang.commons.Result;
import com.kang.service.DialogueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @program: photo_fawu
 * @description:
 * @author: K.faWu
 * @create: 2021-11-23 18:01
 **/
@RestController
@RequestMapping("/dialogue")
public class DialogueController {
    @Autowired
    private DialogueService dialogueService;

    @PostMapping("/saveDialogue")
    public void saveDialogue(Long fromUserId, Long toUserId, String msg, int msgType, int type, int isRead){
        dialogueService.saveDialogue(fromUserId, toUserId, msg, msgType, type, isRead);
    }

    @PostMapping("/getNotReadDialogue")
    public List<Dialogue> getNotReadDialogue(Long fromUserId, Long toUserId){
        return dialogueService.getNotReadDialogue(fromUserId, toUserId);
    }

    @PostMapping("/saveRead")
    public void saveRead(List<Dialogue> list){
        dialogueService.saveRead(list);
    }

    @GetMapping("/{toUserId}")
    public Result<?> getHistoricalNews(@PathVariable("toUserId") Long toUserId, HttpServletRequest request){
        List<Dialogue> list = dialogueService.getHistorIcalNews(toUserId, request);
        return Result.success(list);
    }
}
